
class ProductCaseAttachmentUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick

  process :store_dimensions
  process :resize_to_limit => [1200, 1200]

  def default_resize_url
    self.file.url
  end

  def store_dir
    "product_cases/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  version :thumb do
    process resize_to_fill: [600, 00]
  end

  def store_dimensions
    if file && model
      begin
        model.width, model.height = ::MiniMagick::Image.open(file.file)[:dimensions]
      rescue
        #ignore
      end
    end
  end

end
